/*
 * @Author: 9ilk 3535851673@qq.com
 * @Date: 2025-01-11 22:01:46
 * @LastEditors: 9ilk 3535851673@qq.com
 * @LastEditTime: 2025-01-15 16:36:14
 * @FilePath: /zhuang/ChatServer/UdpServerMain.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */


#include"UdpServer.hpp"
#include"User.hpp"
//./server_udp  localip localport
int main(int argc,char* argv[])
{
    if(argc != 2)
    {
       cerr << "Usage:"<<argv[0] << "localIp localPort" << endl;
       Die(USAGE_ERR);
    }
   // string ip = argv[1];
    uint16_t port = stoi(argv[1]);//转成整数

    ENABLE_CONSOLE_LOG(); //开启日志刷新到显示器
    //用户管理模块
    shared_ptr<UserManager> um = make_shared<UserManager>();
    //网络模块
    std::unique_ptr<UdpServer> svr_uptr = make_unique<UdpServer>(port);
    svr_uptr->InitServer(); //初始化服务器
    //注册服务 新增和转发
    svr_uptr->RegisterService([&um](InetAddr &id){um->AddUser(id);},
    [&um](int sockfd,const string& message){um->Router(sockfd,message);},
    [&um](InetAddr& id){um->DelUser(id);});

    
    svr_uptr->Start();
    return 0;
}